<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 用户数据表模型类
 */
class User_log_login_model extends MY_Model
{
	protected $_table = 'user_log_login';
	protected $primary_key = 'uid';
	protected $protected_attributes = array('uid');

	protected $return_type = 'array';

	public function get_limit($primary_value, $limit = 0)
	{
        //$query = $this->_get_limit($primary_value, $limit);
		$query = $this->db->order_by('logintime', 'DESC')->limit($limit)->get_where($this->_table, array($this->primary_key => $primary_value));
		$pre = $query->first_row('array');
		$last = $query->last_row('array');
		$row['last_login_time'] = $last['logintime'];
		$row['last_login_ip'] = $last['loginip'];
		$row['pre_login_time'] = $pre['logintime'];
		$row['pre_login_ip'] = $pre['loginip'];
		return $row;
	}

    public function get_all($limit, $offset)
    {
        $this->db->order_by('logintime', 'DESC')->limit($limit, $offset);
        return parent::get_all();
    }

	/*
	* private function _get_limit($primary_value, $limit = 0)
	* {
	* $table = $this->db->protect_identifiers($this->_table, TRUE);
	* $primary_value = $this->db->escape($primary_value);
	* $sql = "SELECT * FROM {$table} WHERE {$this->primary_key} = {$primary_value} ORDER BY logintime DESC";
	* $limit && $sql .= ' LIMIT ' . $limit;
	* return $this->db->query($sql);
	* }
	*/
}

/* End of file user_data_model.php */
/* Location: ./application/models/user_data_model.php */
